<!--
 * @Author: your name
 * @Date: 2020-09-25 10:51:57
 * @LastEditTime: 2021-01-26 16:45:03
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wms2\src\views\components\shipmentSelect3.vue
-->
<template>
  <el-select v-model="selectEle" value-key="partyCode" filterable placeholder="请选择" @change="changeValue" :disabled="isDisabled" clearable style="width:100%">
    <el-option
      v-for="item in shipmentList"
      :key="item.partyCode"
      :label="item.userName"
      :value="item"
    />
  </el-select>
</template>
<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      // 选中的对象，这里由于要支持返回对象，所以model中的值是一个对象
      selectEle: {
        partyCode: '',
        userName: '',
      },
      shipmentList: [],
      callbackMethod: '',
      shipmentName: '',
      warehouseCode: '',
    }
  },
  props: {
    isDisabled: {
      type: Boolean,
      default: false
    },
    defaultVal: {
      type: Object,
      default: () => {
        return {
          partyCode: '',
          userName: '',
        }
      }
    }
  },
  watch: {
    defaultVal: {
      handler (obj) {
        this.selectEle = obj
      },
      deep:true
    }
  },
  created() {
    this.findShipmentList()
  },
  methods: {
    init(){

    },
    findShipmentList() {
      return request({
        url: '/wms/warehouseShipment/business/shipments',
        method: 'get',
      }).then(response => {
        this.shipmentList = response.data
        if(this.shipmentList.length === 1){
          this.selectEle = this.shipmentList[0];
          this.$emit("setShipmentInfo", {
            partyCode: this.shipmentList[0].partyCode,
            userName: this.shipmentList[0].userName,
          })
        }
      })
    },

    changeValue(e) {
      this.selectEle = e;
      // this.value = e;
      if (e) {
        // this.$emit("setShipmentInfo", e)
        this.$emit("setShipmentInfo", {
          partyCode: e.partyCode,
          userName: e.userName,
        })
      }
    },
    setSelectValue(warehouseCode, value) {
      this.selectEle = this.shipmentList[0]
    }
  }
}
</script>
